import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-todolist',
  templateUrl: './todolist.component.html',
  styleUrls: ['./todolist.component.scss']
})
export class TodolistComponent implements OnInit {

  public keyWords:string='';
  public toDoList:any[]=[];

  constructor() { }

  ngOnInit(): void {
  }

  doAdd(e:any){
    if(e.keyCode==13){
      let word1=0;
      for (let word of this.toDoList){
        if(this.keyWords==word.title){
          word1=1;
        }
        else
          word1=0;
        
      }
  
      word1==1||this.keyWords==''? this.keyWords='':this.toDoList.push({
        title:this.keyWords,
        status:0                      //0表示待办事务   1表示已完成事项
      }); 
      console.log(this.toDoList)
  
      this.keyWords='';
    }
  }
  deleteData(key:any){
    this.toDoList.splice(key,1);
  }


  toDo(key:any){
    console.log(1);
    this.toDoList[key].status=1;
  }

}
